/*
 * @Author: Du Weixing duweixing@sgsimulation.com
 * @Date: 2024-10-17 15:54:22
 * @LastEditors: Du Weixing duweixing@sgsimulation.com
 * @LastEditTime: 2024-12-05 09:54:22
 * @FilePath: \SGFEM\Solver\SectionCalculator\BeamSection\FormulaMethod\test\BarBeamSectionFormulaCalculatorTest.hpp
 * @Description: 
 * 
 * Copyright (c) 2024 by 神工仿真, All Rights Reserved. 
 */

#pragma once
#include "gtest/gtest.h"
#include "DataStructure/Common/Real.h"
#include "DataStructure/Input/Property/BeamSectionStandardTypes.h"
#include "../Interface/BeamSectionFormulaCalculatorFactory.h"
#include "../Beam/BarBeamSectionFormulaCalculator.h"

using SG::DataStructure::Common::Real;
using namespace SG::DataStructure::FEM;
using SG::FEMSolver::Element::BeamSectionFormulaCalculatorFactory;
using SG::FEMSolver::Element::BarBeamSectionFormulaCalculator;

// 将 BeamSectionFormulaCalculatorFactory 生成对象测试放置在具体截面属性计算中
TEST (BeamSectionFormulaCalculatorFactoryTest, BarSectionCalculatorCreate)
{
    // Test data
    auto calculatorPtr = BeamSectionFormulaCalculatorFactory::Create (BeamSectionStandardTypes::BEAMSECTYPE_BAR);
    auto barCalculatorPtr = dynamic_cast<BarBeamSectionFormulaCalculator*> (calculatorPtr.get ());

    // Check
    ASSERT_TRUE (nullptr != barCalculatorPtr);
}

// PBEAML-BAR 恒截面属性计算测试
TEST (BeamSectionFormulaCalculatorTest, BarSection)
{
    // Input data
    PBEAMLData pBeamL;
    pBeamL.m_id  = 2;
    pBeamL.m_mId = 3;
    pBeamL.SetGroup ("MSCBML0");
    pBeamL.SetBeamSectionStandardTypes (BeamSectionStandardTypes::BEAMSECTYPE_BAR);
    pBeamL.m_section = {{1.0, 0.0, 10.0, {2.0, 3.5}}, {1.0, 1.0, 10.0, {2.0, 3.5}}};

    // Test data
    BarBeamSectionFormulaCalculator calculator;
    auto pBeamTest = calculator.Compute (pBeamL);

    // Target data
    PBEAMData pBeamTarget;
    pBeamTarget.m_id    = 2;
    pBeamTarget.m_mId   = 3;
    pBeamTarget.m_nsges = 1;
    pBeamTarget.m_ccf   = 1;

    Real SO[11] {1.000000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.000000};
    Real XXB[11]{0.000000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.000000};
    Real A[11]  {7.000000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 7.000000};
    Real I1[11] {7.145833, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 7.145833};
    Real I2[11] {2.333333, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.333333};
    Real J[11]  {6.003188, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 6.003188};
    Real NSM[11]{10.00000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.00000};
    std::memcpy (pBeamTarget.m_SO,  SO,  sizeof (SO));
    std::memcpy (pBeamTarget.m_XXB, XXB, sizeof (XXB));
    std::memcpy (pBeamTarget.m_A,   A,   sizeof (A));
    std::memcpy (pBeamTarget.m_I1,  I1,  sizeof (I1));
    std::memcpy (pBeamTarget.m_I2,  I2,  sizeof (I2));
    std::memcpy (pBeamTarget.m_J,   J,   sizeof (J));
    std::memcpy (pBeamTarget.m_NSM, NSM, sizeof (NSM));

    Real C1[11]{ 1.75, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  1.75};
    Real C2[11]{ 1.00, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  1.00};
    Real D1[11]{-1.75, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.75};
    Real D2[11]{ 1.00, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  1.00};
    Real E1[11]{-1.75, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.75};
    Real E2[11]{-1.00, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.00};
    Real F1[11]{ 1.75, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  1.75};
    Real F2[11]{-1.00, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.00};
    std::memcpy (pBeamTarget.m_C1, C1, sizeof (C1));
    std::memcpy (pBeamTarget.m_C2, C2, sizeof (C2));
    std::memcpy (pBeamTarget.m_D1, D1, sizeof (D1));
    std::memcpy (pBeamTarget.m_D2, D2, sizeof (D2));
    std::memcpy (pBeamTarget.m_E1, E1, sizeof (E1));
    std::memcpy (pBeamTarget.m_E2, E2, sizeof (E2));
    std::memcpy (pBeamTarget.m_F1, F1, sizeof (F1));
    std::memcpy (pBeamTarget.m_F2, F2, sizeof (F2));

    pBeamTarget.m_K1 = 0.8333333;
    pBeamTarget.m_K2 = 0.8333333;

    // Check
    ASSERT_TRUE (pBeamTarget == pBeamTest);
}